<?php
require_once('calendar/classes/tc_calendar.php');
unset($_SESSION['addTester']);
unset($_SESSION['addCoder']);
unset($_SESSION['listcomposition']);

if (isset($id)) {
	$query_project = mysql_query("SELECT p.IDProject, p.NameProject, p.Description, p.DateStart, p.DateComplete, p.IDManager, p.`Status`, e.FullName 
        	FROM pr_project p,employee e WHERE p.IDProject='".$id."' and p.IDManager = e.IDEmployee LIMIT 1");
}

$query_employee = mysql_query("SELECT e.IDEmployee,e.FullName  FROM employee e");

function microtime_float()
	{
	    $a= (string)(microtime(true)*1000);
		$b=split('\.',$a);
		return $b[0];
	}
?>

<link href="css/style.css" rel="stylesheet" type="text/css" />
	

<script type="text/javascript">
	$(function(){
		$('#dialogproject').dialog({
			 autoOpen: false,
	            width: 300,
	            modal: true,
	            resizable: false,
	            buttons: {
	                "<?=$l_ok?>": function() {
	                	ajaxDeleteProject();
	                },
	                "<?=$l_cancel?>": function() {
	                    $(this).dialog("close");
	                }
	            }
		});
		//$('#dialogproject').dialog('open');
	});
</script>

<script LANGUAGE="JavaScript" type="text/javascript">
function checkCreateProjectName(ele){
	val = $(ele).val();
	if (val=='') {
		$(ele).focus();
		return false;
	}
	return true;
}


function ajaxCreateProject(ele){
	$.ajax({url:"admin/project/ajaxcreateproject.php", data : $('#formCreate').serializeArray(), success:function(result){
		//alert(result);
		
		window.location.assign("project_admin.php?content=admin/project/list_project.php");
	}});
}

function ajaxUpdateProject(ele){
	$.ajax({url:"admin/project/ajaxupdateproject.php", data : $('#updateproject').serializeArray(), success:function(result){
		alert("<?php echo $l_capnhatthanhcong?>");
		window.location.assign("project_admin.php?content=admin/project/list_project.php");
	}});
}


function focusOnMyInputBox(e,ten){
    var x;
    if(window.event) // IE8 and earlier
    	{
    	x=e.keyCode;
    	}
    else if(e.which) // IE9/Firefox/Chrome/Opera/Safari
    	{
    	x=e.which;
    	}
	if(x==13){
		//document.getElementById(ten).focus();
		return false;
	}else{
		return true;
	}

	
}
</script>
<style>
div.ui-dialog-buttonset button{
	padding:2px 5px !important;
}
.tcday, .tcmonth, .tcyear{
padding: 3px 0;
vertical-align: middle;
font-size: 12px;
}
</style>

<script LANGUAGE="JavaScript" type="text/javascript">
// Popup window code
function newPopup(url) {
	popupWindow = window.open(
		url,'popUpWindow','height=500,width=600,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
<div id="contains" style="background-color: #edf4f7;">

<div class="title"></div>
	<div class="main_content" style="min-height: 895px">
		<div class="tr_title" style="font-size: 14px;font-family: Arial,Verdana,sans-serif;font-weight: bold;"><?=$l_project_new?> </div>
		<?php 
		if (isset($query_project) && (mysql_num_rows($query_project)>0)) {
			while ($row=mysql_fetch_array($query_project)){ 
					$pro_id = $row['IDProject'];
					$pro_name =$row['NameProject'];
					$pro_manager =$row['FullName'];
					$pro_managerid =$row['IDManager'];
					$pro_status = $row['Status'];
					$pro_startdate =$row['DateStart'];
					$pro_completedate =$row['DateComplete'];
					$pro_description = $row['Description'];
		?>
		<form id="updateproject">
		<table class="tcontent" cellpadding="5" cellspacing="0" style="margin-top: 20px">
			<tr>
				<td class="col_left" width="15%"><?=$l_project_code?></td>
				<td>
				<input type="hidden" name="pro_id" value="<?=$pro_id?>"/>
				<div align="left" style="height:24px; width:100%; border:1px solid #c4c0c9;background-color:#F0F0F0;line-height: 24px;"><?php echo $pro_id;?></div>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_project_name?></td>
				<td ><input type="text" id="project_name" name="project_name"  value="<?php echo $pro_name;?>"
					style="height: 24px; width: 100%; border: 1px solid #c4c0c9;line-height: 24px;font-size: 12px;" />
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_manager?></td>
				<td >
					<div align="left">
						<select class="com_tit" name="project_manager" id="project_manager" style="width: 197px;line-height: 24px;font-size: 12px;">
						  <?php 
						  while ($rowe = mysql_fetch_array($query_employee)) {
						  	?>
						  	<option <?if($pro_managerid==$rowe['IDEmployee']){?> selected="selected" <?}?> value="<?=$rowe['IDEmployee']?>"><?=$rowe['FullName']?></option>
						  <?php }
						  ?>
                    	</select>
					</div>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_start_date?></td>
				<td >
				<?php
				$myCalendar1 = new tc_calendar("start_date", true);
				$myCalendar1->setIcon("calendar/images/iconCalendar.gif");
				$dates = split(" ", $pro_startdate , 2);
				$d=split('-',$dates[0],3);
					
				$myCalendar1->setDate($d[2],$d[1],$d[0]);
				$myCalendar1->setPath("calendar/");
				$myCalendar1->setYearInterval(2010, 2015);
				$myCalendar1->dateAllow('2010-01-01', '2015-12-31');
				//$myCalendar1->setHeight(350);
				//$myCalendar1->autoSubmit(true, "form1");
				//$myCalendar1->setSpecificDate(array("2011-04-01", "2011-04-13", "2011-04-25"), 0, 'month');
				$myCalendar1->setOnChange("myChanged('test')");
				//$myCalendar->rtl = true;
				$myCalendar1->writeScript();
					
				//echo $myCalendar1->getDate();

				?>
				<input type="hidden" name="starttime" id="starttime"/>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_complete_date?></td>
				<td >
					<?php
				$myCalendar1 = new tc_calendar("complete_date", true);
				$myCalendar1->setIcon("calendar/images/iconCalendar.gif");
				$dates = split(" ", $pro_completedate , 2);
				$d=split('-',$dates[0],3);
				$myCalendar1->setDate($d[2],$d[1],$d[0]);
				$myCalendar1->setPath("calendar/");
				$myCalendar1->setYearInterval(2010, 2015);
				$myCalendar1->dateAllow('2010-01-01', '2015-12-31');
				//$myCalendar1->setHeight(350);
				//$myCalendar1->autoSubmit(true, "form1");
				//$myCalendar1->setSpecificDate(array("2011-04-01", "2011-04-13", "2011-04-25"), 0, 'month');
				$myCalendar1->setOnChange("myChanged('test')");
				//$myCalendar->rtl = true;
				$myCalendar1->writeScript();
					
				//echo $myCalendar1->getDate();

				?>
				<input type="hidden" name="completetime" id="completetime"/>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_status?></td>
				<td >
					<div align="left">
						<select class="com_tit" name="pro_status" id="pro_status" style="width: 197px">
	                          <option value="0" <?if($pro_status==0){?> selected="selected" <?}?>><?php echo $l_status_project_no;?></option>
	                          <option value="1" <?if($pro_status==1){?> selected="selected" <?}?>><?php echo $l_status_project_done;?></option>
	                    </select>
                    </div>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_description?></td>
				<td>
				<textarea rows="8" cols="5" id="pro_description" name="pro_description" 
						style="width: 100%; border: 1px solid #c4c0c9;font-size: 12px;"><?php echo $pro_description;?></textarea>
				</td>
			</tr>
		</table>
		</form>
		<div align="right">
				<input class="buttonProject" type="button" onclick="if(checkCreateProjectName($('#updateproject').find('#project_name'))){ajaxUpdateProject(this)}" style="margin: 5px 0;font-size: 12px;" value="<?=$l_update?>" />
				<a href="project_admin.php?content=admin/project/list_project.php"><span class="buttonProject" style="padding: 5px; border:1px solid #999;font-size: 12px;"><?php echo $l_cancel;?></span></a>
				<!-- input class="buttonProject" type="button" onclick="$('#dialogproject').dialog('open')" style="margin: 5px 0;" value="" /-->
		</div>
		<div id="dialogproject" title="Confirm">
			<p><?=$l_confirm_deleteproject?></p>
		</div>
		<?php 
			}}else{
				$pro_id = microtime_float();
				$pro_startdate = date('Y-m-d h:m:s',time());
				$pro_completedate = date('Y-m-d h:m:s',time()+(7*24*60*60));
		?>
		<form id="formCreate" action="admin/project/handlecreateproject.php" method="post">
		<table class="tcontent" cellpadding="5" cellspacing="0" style="margin-top: 20px">
			<tr>
				<td class="col_left" width="15%"><?=$l_project_code?></td>
				<td>
				<input type="hidden" name="pro_id" value="<?=$pro_id?>"/>
				<div align="left" style="height:24px; width:100%; border:1px solid #c4c0c9;background-color:#F0F0F0;line-height: 24px;"><?php echo $pro_id;?></div>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_project_name?></td>
				<td ><input type="text" id="project_name" name="project_name"  value="<?php echo $ftitle;?>"
					style="height: 24px; width: 100%; border: 1px solid #c4c0c9;font-size: 12px;" />
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_manager?></td>
				<td >
					<div align="left">
						<select class="com_tit" name="project_manager" id="project_manager" style="width: 197px;font-size: 12px;">
							  <?php 
							  while ($row = mysql_fetch_array($query_employee)) {
							  	?>
							  	<option value="<?=$row['IDEmployee']?>"><?=$row['FullName']?></option>
							  <?php }
							  ?>
	                    </select>
                    </div>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_start_date?></td>
				<td >
				<?php
				$myCalendar1 = new tc_calendar("start_date", true);
				$myCalendar1->setIcon("calendar/images/iconCalendar.gif");
				$dates = split(" ", $pro_startdate , 2);
				$d=split('-',$dates[0],3);
					
				$myCalendar1->setDate($d[2],$d[1],$d[0]);
				$myCalendar1->setPath("calendar/");
				$myCalendar1->setYearInterval(2010, 2015);
				$myCalendar1->dateAllow('2010-01-01', '2015-12-31');
				//$myCalendar1->setHeight(350);
				//$myCalendar1->autoSubmit(true, "form1");
				//$myCalendar1->setSpecificDate(array("2011-04-01", "2011-04-13", "2011-04-25"), 0, 'month');
				$myCalendar1->setOnChange("myChanged('test')");
				//$myCalendar->rtl = true;
				$myCalendar1->writeScript();
					
				//echo $myCalendar1->getDate();

				?>
				<input type="hidden" name="starttime" id="starttime"/>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_complete_date?></td>
				<td >
					<?php
				$myCalendar1 = new tc_calendar("complete_date", true);
				$myCalendar1->setIcon("calendar/images/iconCalendar.gif");
				$dates = split(" ", $pro_startdate , 2);
				$d=split('-',$dates[0],3);
					
				$myCalendar1->setDate($d[2],$d[1],$d[0]);
				$myCalendar1->setPath("calendar/");
				$myCalendar1->setYearInterval(2010, 2015);
				$myCalendar1->dateAllow('2010-01-01', '2015-12-31');
				//$myCalendar1->setHeight(350);
				//$myCalendar1->autoSubmit(true, "form1");
				//$myCalendar1->setSpecificDate(array("2011-04-01", "2011-04-13", "2011-04-25"), 0, 'month');
				$myCalendar1->setOnChange("myChanged('test')");
				//$myCalendar->rtl = true;
				$myCalendar1->writeScript();
					
				//echo $myCalendar1->getDate();

				?>
				<input type="hidden" name="completetime" id="completetime"/>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_status?></td>
				<td>
					<div align="left">
						<select class="com_tit" name="pro_status" id="pro_status" style="width: 197px;font-size: 12px;">
	                          <option value="0"><?php echo $l_status_project_no;?></option>
	                          <option value="1"><?php echo $l_status_project_done;?></option>
	                    </select>
                    </div>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_description?></td>
				<td>
				<textarea rows="8" cols="5" id="pro_description" name="pro_description" 
						style="width: 100%; border: 1px solid #c4c0c9;font-size: 12px;"><?php echo $fdescription;?></textarea>
				</td>
			</tr>
		</table>
		
		<div align="right">
				<input class="buttonProject" type="submit" onclick="return checkCreateProjectName($('#formCreate').find('#project_name'));" style="margin: 5px 0;font-size: 12px;" value="<?=$l_create?>" />
				<input class="buttonProject" type="reset" style="margin: 5px 0;font-size: 12px;" value="<?=$l_reset?>" />
			</div>
		</form>
		<?php }?>
	
	</div>
	
</div>
